package com.hhq.controller;

import com.hhq.entity.Job;
import com.hhq.service.Jobservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class JobController {
    @Autowired
    private Jobservice jobservice;
    @RequestMapping("/getAllJob")
    public String getAllJob(Model model){
        List<Job> list = jobservice.getAllJob();
        model.addAttribute("requestScopelist",list);
        System.out.println(list );
        return "job/list";
    }

    @RequestMapping("/findJobByName")
    public String findJobByName(Model model, String name, HttpServletRequest request){
        List<Job> list = jobservice.findJobByName(name);
        System.out.println(list);
        if (list.size()!=0){
            model.addAttribute("requestScopelist",list);
            return "job/list";
        }
        else {
            request.setAttribute("message","不存在该用户，请重新输入！");
            return "forward:/getAllJob";
        }
    }


    @RequestMapping("/toAddJob")
    public String toAddJob(){
        return "job/add";
    }

    @RequestMapping("/addJob")
    public String addJob(Job job){
        int num = jobservice.addJob(job);
        System.out.println(job);
        System.out.println(num);
        return "forward:/getAllJob";
    }

    @RequestMapping("/toeditJob")
    public String toeditJob(){
        return "job/editJob";
    }

    @RequestMapping("/deleteJob")
    public String deleteJob(String name){
        jobservice.deleteJob(name);
        System.out.println("Yes");
        return "forward:/getAllJob";
    }

    @RequestMapping("/updateJob")
    public String updateJob(Job job){
        int num=jobservice.updateJob(job);
        System.out.println(num);
        return "forward:/getAllJob";
    }

}
